import { Store } from 'redux';

import start from './start';

import { ModelOptions } from './types';

import createStore, { createPersistReducer } from './store';

export default class dva {
  static store: Store;

  private _store: Store;

  constructor(opts?: ModelOptions) {
    this._store = createStore(opts);
    dva.store = this._store;
  }

  public getStore = () => this._store;

  public start = (Component: any) => (
    start(this.getStore())(Component)
  );

  public use = <State = any>(opts: ModelOptions) => {
    const reducers = createPersistReducer<State>(opts);
    this.getStore().replaceReducer(reducers);
  }
}


